Rock Paper Scissors code

#include #include #include using namespace std; int main() { srand(static_cast(time(0))); // Seed random generator string choices[3] = {"Rock", "Paper", "Scissors"}; int computerChoice = rand() % 3; int userChoice; cout << "🎮 Rock, Paper, Scissors Game\n"; cout << "Choose one:\n"; cout << "0 - Rock\n"; cout << "1 - Paper\n"; cout << "2 - Scissors\n"; cout << "Enter your choice: "; cin >> userChoice; if (userChoice < 0 || userChoice > 2) { cout << "Invalid input. Please enter 0, 1, or 2.\n"; return 1; } cout << "You chose: " << choices[userChoice] << endl; cout << "Computer chose: " << choices[computerChoice] << endl; // Determine winner if (userChoice == computerChoice) { cout << "It's a draw!\n"; } else if ((userChoice == 0 && computerChoice == 2) || (userChoice == 1 && computerChoice == 0) || (userChoice == 2 && computerChoice == 1)) { cout << "You win!\n"; } else { cout << "Computer wins!\n"; } return 0; }

Code output

🎮 Rock, Paper, Scissors Game Choose one: 0 - Rock 1 - Paper 2 - Scissors Enter your choice: 2 You chose: Scissors Computer chose: Paper You win!